package com.web.wrapper;

import java.io.Serializable;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Objects;
import com.web.exception.CephWebException;
/**
 * @author dell2
 *
 */
public class RbdParameter implements Serializable{
	/**
	 * {
			"imageName" : "foo",
			"pool" : "rbd",
			"sessionid" : "username",
			"size" : 0
		}
	 */
	private static final long serialVersionUID = 1L;
	private String pool;
	private String imageName;
	private long size ; //in bytes
	private String sessionid ;
	
	public RbdParameter() {
		// TODO Auto-generated constructor stub
	}
	public RbdParameter(String pool,String imageName,String sessionid) {
		this.pool = pool;
		this.imageName = imageName;
		this.sessionid = sessionid ;
	}
	
	
	public String getPool(boolean required) throws Exception {
		required (required ,pool) ;
		return pool;
	}
	public void setPool(String pool) {
		this.pool = pool;
	}
	public long getSize() {
		return size;
	}
	public void setSize(long size) {
		this.size = size;
	}
	public String getSessionid() {
		if( null == this.sessionid ){
			this.sessionid = "ceph" ;
		}
		return sessionid;
	}
	public void setSessionid(String sessionid) {
		this.sessionid = sessionid;
	}
	@Override
	public String toString() {
		return JSONObject.toJSONString(this);
	}
	public String getImageName(boolean required) throws Exception {
		required (required ,imageName) ;
		return imageName;
	}
	public void setImageName(String imageName) {
		this.imageName = imageName;
	}
	
	public static void main(String[] args) {
		System.out.println( new RbdParameter("rbd","foo","username").toString() );
	}
	
	private void required(boolean req,Object filed) throws Exception{
		if( req && null == filed){
			throw new NullPointerException("Can not be null") ;
		}
	}

}
